package cn.itsub.sodo.view;

import java.awt.Component;
import java.awt.Frame;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import cn.itsub.sodo.core.types.Size;

public abstract class HiView {
	protected Frame frame = null;				//窗体
	protected float updateInterval = 1.0f/60;	//绘图更新周期（秒）
	protected Size frameSize = null;			//窗体尺寸
	protected Size designSize = null;			//设计尺寸
	protected boolean isFullScreen = false;		//当前是否全屏
	//protected boolean isRunning = false;		//是否正在运行
	protected Component canvas = null;

	/**
	 * 进入全屏 / 退出全屏
	 * @param full
	 */
	public void setFullScreenWindow(boolean full){
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();  
		GraphicsDevice gd = ge.getDefaultScreenDevice();
		if(!isFullScreen&&full){
			
			frame.dispose();
			frame.setUndecorated(true);
			frame.setVisible(true);
			gd.setFullScreenWindow(frame);
			this.isFullScreen = true;
			return;
		}
		if(isFullScreen&&!full){
			gd.setFullScreenWindow(null);
			frame.dispose();
			frame.setUndecorated(false);
			frame.setVisible(true);
			this.isFullScreen = false;
			return;
		}
	}
	public void repaint(){
		//frame.repaint(0,0,frame.getWidth(),frame.getHeight());
		if(canvas!=null)
		this.canvas.repaint(0, 0, frame.getWidth(), frame.getHeight());
	}
	public Frame getFrame(){
		return this.frame;
	}
	public void setFrameSize(Size frameSize){
		this.frameSize = new Size();
		this.frameSize.set(frameSize);
	}
	public void setFrameSize(float width,float height){
		this.frameSize = new Size();
		this.frameSize.set(width, height);
	}
	public void setDesignSize(Size frameSize){
		this.designSize = new Size();
		this.designSize.set(frameSize);
	}
	public void setDesignSize(float width,float height){
		this.designSize = new Size();
		this.designSize.set(width, height);
	}
	public Size getFrameSize(){
		return new Size(frameSize.width, frameSize.height);
	}
	public Size getDesignSize(){
		return new Size(designSize.width, designSize.height);
	}
	
	public abstract HiView init(Size frameSize,Size designSize);

}
